// 单按钮弹窗
Component({
  properties: {
    modalHidden: {    //弹窗显示与隐藏
      type: Boolean,
      value: true
    },
    popupConfig:{
      type: Object,
      value: {
        title: '服务评价'
      }
    },
    evaluate: {
      type: Object,
      value:{
        0:'未选择',
        1: '非常不满意',
        2: '不满意',
        3: '一般',
        4: '满意',
        5: '非常满意'
      }
    },
    contentConfig:{
      type: Object,
      value: {
        scoreArray: [
            {
              code: 'design_scheme',
              title: '设计方案',
              allstars: 5,
              selected: 0,
              index:0
            },
            {
              code: 'work_efficiency',
              title: '工作效率',
              allstars: 5,
              selected: 0,
              index: 1
            },
            {
              code: 'service_attitude',
              title: '服务态度',
              allstars: 5,
              selected: 0,
              index: 2
            }
        ],
        starsize:'44rpx',
        paddingleft:'60rpx',
        marginleft:'282rpx'
      }
    },
    supDescribe:{   //补充描述
      type:String,
      value:''
    }
  },
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  data: {
    // 这里是一些组件内部数据  
    btndisabled: true,
  },
  methods: {
    /**
     * author：xujun
     * @desc 选中星星
     * @param {event} evt - 事件对象
     * @param {number} item - 选中的索引
     * @param {Boolean} type - 判断是选中的还是未选的
     * */
    selectedStar: function (event){
      let selectedData = event.currentTarget.dataset
      let index = selectedData.item.index 
      if (selectedData.type){
        selectedData.item.selected = selectedData.index + 1
      }else{
        selectedData.item.selected = selectedData.item.selected + selectedData.index+1
      }
      this.data.contentConfig.scoreArray[index] = selectedData.item
      this.setData({
        contentConfig: this.data.contentConfig
      })
      //更变提交按钮状态
      if (this.data.btndisabled){
        this.queryStar()
      }
    },
    /**
     * author：xujun
     * @desc 提交是否失效
     * */
    queryStar:function(){
      let btndisabled = true
      for (let i = 0; i < this.data.contentConfig.scoreArray.length; i++) {
        if (this.data.contentConfig.scoreArray[i].selected == 0) {
          btndisabled = false
          break
        }
      }
      if (btndisabled) {
        this.setData({
          btndisabled: false
        })
      }
      return btndisabled
    },
    //提交回调
    submit:function(){
      //全局更新数据
      wx.eventBus.trigger('getSupDescribe', this.data)
      wx.eventBus.trigger('getOrderEvaluate', this.data)
      this.triggerEvent('submitEvent')
    },
    inputText:function(e){
      this.data.supDescribe = e.detail.value
    },
    //关闭回调
    _closeback:function(){
      this.triggerEvent('cancelEvent')
    }
  }
})  